package com.steakliu.sun.common.util;

import java.util.stream.IntStream;

/**
 * 功能说明：
 * <p>
 * Original @Author: steakliu-刘牌, 2023-01-08  12:54
 * <p>
 * Copyright (C)2020-2022  steakliu All rights reserved.
 */
public class CodecUtil {
    /**
     * 序列化类型最大长度
     */
    public static int SERIALIZER_MAX_LEN = 16;

    /**
     * 序列化类型长度不足16byte，使用0进行填充
     * @param serializer
     * @return
     */
    public static String fillZero(String serializer) {
        int length = serializer.length();
        StringBuilder builder = new StringBuilder(serializer);
        if (length < SERIALIZER_MAX_LEN) {
            IntStream.range(0, SERIALIZER_MAX_LEN - length).forEach((i) -> {
                builder.append('0');
            });
        }
        return builder.toString();
    }

    public static String getSerializerStr(String serializer){
        return serializer.replace("0","");
    }
}
